

var ctx = ctx;
var abstainingNo;//弃权编号

//今天开始 or 明天开始
var alertAction = "actionStartToDay";

var startDekaronId = "";

//window.onload = function() {
//	/** 屏蔽微信分享功能 */
//	document.addEventListener('WeixinJSBridgeReady',
//			function onBridgeReady() {
//				WeixinJSBridge.call('hideOptionMenu');
//			});
//	//ajaxLoadData();
//	//init();
//};

//获取XmlHttpRequest对象
function createXmlHttpRequest(){
	if(window.ActiveXObject){
	    return new ActiveXObject("Microsoft.XMLHTTP");
	}else if(window.XMLHttpRequest){
	    return new XMLHttpRequest();
	}
}

//跳转到挑战页面
function toDekaronPage(){

	parent.document.title = "挑战";
	var dekaronId=document.getElementById("dekaronId").value;
	
	var memberId = parent.document.getElementById("memberId").value;
	
	var openId = parent.document.getElementById("openId").value;
	
	parent.window.location.href="/page/challenge?memberId="+memberId+"&&dekaronId="+dekaronId+"&&openId="+openId;
	document.getElementById("dekaronId").value="";
}

//跳转到京东购买页
function toJDBuyPage(){
	window.location.href=ctx+"/v3/pedometer/match/buy.html";
}


//隐藏DIV
function hiddenDiv(id){
	document.getElementById(id).style.display="none";
}

//显示DIV
function showDiv(id){
	document.getElementById(id).style.display="block";
	console.log(document.getElementById(id).style.display)
}

//隐藏所有Div
function hiddenAllDiv(){
	hiddenDiv("send_accept_1");
	hiddenDiv("send_accept_2");
	hiddenDiv("send_accept_3");
	
	hiddenDiv("giveUp_div_1");
	hiddenDiv("giveUp_div_2");
	hiddenDiv("giveUp_div_3");
	
	hiddenDiv("challengeFail_div");
	hiddenDiv("challengeSussecc_div");
	

	hiddenDiv("showTorChallengeInfoDiv_1");
	hiddenDiv("showTorChallengeInfoDiv_2");
	hiddenDiv("showTorChallengeInfoDiv_3");
	
	hiddenDiv("index_noPoint_div");
	hiddenDiv("index_allSuccessInfo_div");
	
}

//无刷新加载数据
function ajaxLoadData(){
	
	var mod_dekaron=document.getElementById("mod-dekaron");
	mod_dekaron.addEventListener("click", toDekaronPage(), false);
	
	//var memberId = document.getElementById("memberId_hidden").value;
	var pedometerOpenId = document.getElementById("pedometeropenId").value;
	var weightopenId=document.getElementById("weightopenId").value;
	var xhr = createXmlHttpRequest();
	xhr.onreadystatechange = function() {
		
		if (xhr.readyState == 4) {
			if (xhr.status == 200) {
				var json = xhr.responseText;
				var jsonData = eval( "(" + json + ")" );//转换后的JSON对象
				init(jsonData);
			}
		}
	};
	var url = '/api/ajax/getChallenge';
	xhr.open("post", url + "?pedometerOpenId=" + pedometerOpenId+"&mathNum="+Math.random()+"&&dekaronId="+"&&weightopenId="+weightopenId, true);
	xhr.send();
}

//初始化数据
//(0:推送数据,1:今天开始,2:成功信息,3:失败信息,4:几分不够信息,5:明天开始信息,6:没有绑定设备信息)
function init(data){
	hiddenAllDiv();
	var status=data.status;
	//status=6;
	switch(status){
		case 0:
			sendChallenge(data);
			break;
		case 1:
			showStartToday(data);
			break;
		case 2:
			showSuccessInfo(data);
			break;
		case 3:
			showFailInfo(data);
			break;
		case 4:
			showNoPoint(data);
			break;
		case 5:
			showStartTomorrow(data);
			break;
		case 6:
			showAllSuccessInfo();
			break;
	}
	
}

//显示没有绑定设备提示信息
function showAllSuccessInfo(){
	hiddenAllDiv();
	showDiv("index_allSuccessInfo_div");
}

//显示积分不够的信息
function showNoPoint(data){
	hiddenAllDiv();
	showDiv("index_noPoint_div");
	var pointText=document.getElementById("index_noPoint_text");
	pointText.innerHTML=data.dekaron.bet;
}

//推送消息
function sendChallenge(data){
	
	hiddenAllDiv();
	
	var dekaronId=data.dekaron.id;
	var dekaronIdHidden=document.getElementById("dekaronId");
	dekaronIdHidden.value=dekaronId;
	
	var template=data.dekaron.template;
	
	switch(template){
	
		case 1:
			bingDataForSend(data);
			showDiv("send_accept_1");
			
			break;
			
		case 2:
			bingDataForSend(data);
			showDiv("send_accept_2");
			
			break;
			
		case 3:
			bingDataForSend(data);
			showDiv("send_accept_3");
			break;
	}
}

//绑定推送消息的数据
function bingDataForSend(data){
	
	var type=data.dekaron.valueType;
	var template=data.dekaron.template;
	if (type == 1) {
		var stepValue = data.dekaron.stepValue >= 10000 ? (data.dekaron.stepValue / 10000 + "&nbsp;万"): data.dekaron.stepValue+"&nbsp;";
		document.getElementById("step_text_begin_"+template).innerHTML = stepValue
				+ "步";
	}

	else if (type == 2) {

		document.getElementById("step_text_begin_"+template).innerHTML = data.dekaron.calorieValue
				+ "&nbsp;大卡";
	}

	else if (type == 3) {

		document.getElementById("step_text_begin_"+template).innerHTML = data.dekaron.distanceValue
				+ "&nbsp;公里";
	}
	
	document.getElementById("day_text_begin_"+template).innerHTML = data.dekaron.finishTime
		+ "&nbsp;天";
	document.getElementById("level_text_begin_"+template).innerHTML = data.dekaron.level
		+ "&nbsp;级";
	document.getElementById("bonus_text_begin_"+template).innerHTML = data.dekaron.bonus
		+ "&nbsp;分";
	document.getElementById("bet_text_begin_"+template).innerHTML = data.dekaron.bet
		+ "&nbsp;分";
	
	//bingDataForPrototype(data);
}


//显示挑战成功信息
function showSuccessInfo(data){
	showDiv("challengeSussecc_div");
	//document.getElementById("dekaronMemberId_hidden").value=data.dm.id;
	//var dekaronMemberId=document.getElementById("dekaronMemberId_hidden");
	//dekaronMemberId.value=
	
	
	var successPoint=document.getElementById("successPoint");
	
	var template=data.dekaron.template;
	var bouns=data.dekaron.bonus;
	successPoint.innerHTML=bouns+"分";
	if(template==2){
		//successPoint.innerHTML=bouns+"分";
		//showDiv("challengeTaget_div_2");
	}
	else{
		//showDiv("challengeTaget_div_1");
	}
	
	//bingDataForPrototype(data);
}

//显示挑战失败信息(1:周，2:累计,3:月)
function showFailInfo(data){
	
	showDiv("challengeFail_div");
	
	var template=data.dekaron.template;
	switch(template){
		case 1:
			//showDiv("challengeTaget_div_1");
			break;
		case 2:
			//showDiv("challengeTaget_div_2");
			break;
		case 3:
			//showDiv("challengeTaget_div_1");
			break;
	
	}
	
	failTypeTemplate(data);
}

//不同模板不同类型的失败信息
function failTypeTemplate(data){
	var dekaronInfo=data.dm;
	var template=data.dekaron.template;
	var type=data.dekaron.valueType;
	var bet=data.dekaron.bet;
	var failInfo=document.getElementById("failInfo_div");
	
	var rewardInfo="";
	
	if (template == 1 || template==3) {
		var finishday = dekaronInfo.fail_info;
		rewardInfo = '遗憾！本次挑战你只坚持了<span class="day_text color_text">'
				+ finishday + '天</span>。' + bet + '分押注已被没收。';
	} else if (template == 2) {
		if (type == 1) {
			var finishStep = dekaronInfo.fail_info;
			if (finishStep == 0) {
				finishStep += "步";
			}
			rewardInfo = '遗憾！本次挑战你只完成了<span class="day_text color_text">'
					+ finishStep + '</span>。' + bet + '分押注已被没收。';
		}

		else if (type == 2) {
			var finishCalories = dekaronInfo.fail_info;
			if (finishCalories == 0) {
				finishCalories += "大卡";
			}
			rewardInfo = '遗憾！本次挑战你只完成了<span class="day_text color_text">'
					+ finishCalories + '</span>。' + bet + '分押注已被没收。';
		}

		else if (type == 3) {
			var finishDistance = dekaronInfo.fail_info;
			if (finishDistance == 0) {
				finishDistance += "公里";
			}
			rewardInfo = '遗憾！本次挑战你只完成了<span class="day_text color_text">'
					+ finishDistance + '</span>。' + bet + '分押注已被没收。';
		}
	}
	
	failInfo.innerHTML=rewardInfo;
}



//显示今天开始的模板
function showStartToday(data){
	hiddenAllDiv();
	var template=data.dekaron.template;
	switch(template){
	
		case 1:
			tdWeekTemplate();
			bingDataForWeek(data);
			
			break;
			
		case 2:
			tdCountTemplate();
			bingDataForCount(data);
			
			break;
			
		case 3:
			tdMonthTemplate();
			bingDataForMonth(data);
			
			break;
		
	}
}

//显示今天开始周模板
function tdWeekTemplate(){
	showDiv("giveUp_div_1");
	//showDiv("challengeTaget_div_1");
	
}

//显示今天开始月模板
function tdMonthTemplate(){
	showDiv("giveUp_div_3");
	//showDiv("challengeTaget_div_1");
}

//显示今天开始累计模板
function tdCountTemplate(){
	showDiv("giveUp_div_2");
	
	//showDiv("challengeTaget_div_2");
}

//绑定挑战进行中周模板数据
function bingDataForWeek(data){
	//挑战天数
	var dekaronDay = data.updateRecordDay;
	
	var nowDay=data.dekaronDay;
	
	var isFinish =data.isfinish;
	
	var type = data.dekaron.valueType;
	
	var detail = '';
	
	//dekaronDay=8;
	
	if(isFinish==0){
		if(dekaronDay==0){
			dekaronDay=dekaronDay+1;
		}
	}
	
	
//	var dayStr = '第<span class="bottom_text" id="reward_day_running_1">'
//		+ dekaronDay + '</span>天，';
	var dayStr="";
	var sel = "";
	if (type == 1) {
		var finishStep = data.dekaron.stepValue;
		//挑战步数
		var dekaronStep = data.fulfill;

		var stepValue = finishStep - dekaronStep;

		if (stepValue <= 0) {
			detail = dayStr + '今天任务已完成';
			sel = "selected";
		} else {
			
//			detail = dayStr
//					+ '今天还差<span class="bottom_text" id="reward_step_running_1">'
//					+ stepValue + '步</span>，加油！';
			detail=dayStr+'今天还差&nbsp;<span class="bottom_text" style="font-size: 20px;">'+stepValue+'</span><span style="color: #f7882d;">&nbsp;步</span>';
			sel = "unselected";
			
		}
	}
	if (type == 2) {
		
		var finishCalories = data.dekaron.calorieValue;
		var dekaronCalories = data.fulfill;
		var calories = getDecimalOne(finishCalories - dekaronCalories);
		
		if (calories <= 0) {
			detail = dayStr + '今天任务已完成';
			sel = "selected";
		} else {
//			detail = dayStr
//					+ '今天还差<span class="bottom_text" id="reward_step_running_1">'
//					+ calories + '大卡</span>，加油！';
			detail=dayStr+'今天还差&nbsp;<span class="bottom_text" style="font-size: 20px;">'+calories+'</span><span style="color: #f7882d;">&nbsp;大卡</span>';
			sel = "unselected";
			
		}
	}

	if (type == 3) {
		var distanceValue = data.dekaron.distanceValue;
		var dekaronDistance = data.fulfill;
		var distance=(distanceValue - dekaronDistance).toFixed(2);
		//var distance = getDecimalOne(distanceValue - dekaronDistance);
		
		if (distance <= 0) {
			detail = dayStr + '今天任务已完成';
			sel = "selected";
		} else {
//			detail = dayStr
//					+ '今天还差<span class="bottom_text" id="reward_step_running_1">'
//					+ distance + '公里</span>，加油！';
			detail=dayStr+'今天还差&nbsp;<span class="bottom_text" style="font-size: 20px;">'+distance+'</span><span style="color: #f7882d;">&nbsp;公里</span>';
			sel = "unselected";
			
		}
	}
	
	if(nowDay>7){
		var day=7-(nowDay-8);
		if(day==1){
			detail='挑战将在今天过期，请及时同步数据！';
		}
		else{
			detail='<span style="margin-left:5px;">挑战将在'+day+'天后过期，请及时同步数据！</span>';
		}
	}

	var rewardInfo = document.getElementById('challenge_reward_running_1');
	rewardInfo.innerHTML = detail;
	
	
	for (var i = 1; i <= 7; i++) {
		var dateArray = document.getElementById("date_running_1_" + i);

		var day = dateArray.innerHTML;
		var dayValue = day.replace(new RegExp("&nbsp;", 'g'), "");
		if (dayValue == dekaronDay) {
			dateArray.className = 'challenge_date_running ' + sel;
		} else if (dekaronDay < i) {
			dateArray.className = 'challenge_date_running';
		} else if (dekaronDay > i) {
			dateArray.className = 'challenge_date_running selected';
		}
	}
	
}

//绑定挑战进行中月模板数据
function bingDataForMonth(data){
	var sl = document.getElementById("date_running_3_sl2");
	var sl1 = document.getElementById("date_running_3_sl1");
	var type=data.dekaron.valueType;
	var dekaronDay = data.updateRecordDay;
	
	var nowDay=data.dekaronDay;
	
	var isFinish =data.isfinish;
	var detail = '';
	var sel = '';
	
	if(isFinish==0){
		if(dekaronDay==0){
			dekaronDay=dekaronDay+1;
		}
	}
	
//	var dayStr = '第<span class="bottom_text" id="reward_day_running_1">'
//			+ dekaronDay + '</span>天，';
	var dayStr="";
	if (type == 1) {
		var finishStep = data.dekaron.stepValue;
		//挑战步数
		var dekaronStep = data.fulfill;
		//					var stepValue= (finishStep - dekaronStep)>10000 ? (getInt((finishStep - dekaronStep)/10000) +"万步") : (getInt(finishStep - dekaronStep) +"步");
		var stepValue = showDecimalOne(finishStep - dekaronStep);
		if (stepValue <= 0) {
			detail = dayStr + '今天任务已完成';
			sel = "selected";
		} else {
//			detail = dayStr
//					+ '今天还差<span class="bottom_text" id="reward_step_running_1">'
//					+ stepValue + '步</span>，加油！';
			detail=dayStr+'今天还差&nbsp;<span class="bottom_text" style="font-size: 20px;">'+stepValue+'</span><span style="color: #f7882d;">&nbsp;步</span>';
			sel = "unselected";
		}
		
	}

	if (type == 2) {
		var finishCalories = data.dekaron.calorieValue;
		var dekaronCalories = data.fulfill;
		//					var calories = (finishCalories - dekaronCalories)<1 ? (getInt(((finishCalories - dekaronCalories)*1000).toFixed(1)) + "卡") :  (getInt(finishCalories - dekaronCalories) + "大卡");
		var calories = showDecimalOne(finishCalories - dekaronCalories);
		if (calories <= 0) {
			detail = dayStr + '今天任务已完成';
			sel = "selected";
		} else {
//			detail = dayStr
//					+ '今天还差<span class="bottom_text" id="reward_step_running_1">'
//					+ calories + '大卡</span>，加油！';
			detail=dayStr+'今天还差&nbsp;<span class="bottom_text" style="font-size: 20px;">'+calories+'</span><span style="color: #f7882d;">&nbsp;大卡</span>';
			sel = "unselected";
		}
	}

	if (type == 3) {
		var distanceValue = data.dekaron.distanceValue;
		var dekaronDistance = data.fulfill;
		//					var distance = (distanceValue - dekaronDistance)<1000 ? getInt(((distanceValue - dekaronDistance)*1000).toFixed(1) + "米" ) : (getInt(distanceValue - dekaronDistance)+"公里");
		//var distance = showDecimalOne(distanceValue - dekaronDistance);
		var distance=(distanceValue - dekaronDistance).toFixed(2);
		if (distance <= 0) {
			detail = dayStr + '今天任务已完成';
			sel = "selected";
		} else {
//			detail = dayStr
//					+ '今天还差<span class="bottom_text" id="reward_step_running_1">'
//					+ distance + '公里</span>，加油！';
			detail=dayStr+'今天还差&nbsp;<span class="bottom_text" style="font-size: 20px;">'+distance+'</span><span style="color: #f7882d;">&nbsp;公里</span>';
			sel = "unselected";
		}
	}
	
	if(nowDay>30){
		var day=7-(nowDay-31);
		if(day==1){
			detail='挑战将在今天过期，请及时同步数据！';
		}
		else{
			detail='<span style="margin-left:5px;">挑战将在'+day+'天后过期，请及时同步数据！</span>';
		}
		
	}

	var rewardInfo = document.getElementById('challenge_reward_running_3');
	rewardInfo.innerHTML = detail;

	for (var i = 0; i < 5; i++) {
		var dateArray = document
				.getElementById("date_running_3_" + (5 - i));

		if (dekaronDay == 30) {
			dateArray.innerHTML = dekaronDay - i - 1;
		} else if (dekaronDay < 5) {
			dateArray.innerHTML = 5 - i;
		} else {
			dateArray.innerHTML = dekaronDay - i;
		}

		if (dekaronDay < 5) {
			if (dateArray.innerHTML == dekaronDay) {
				dateArray.className = 'challenge_date_running_3 ' + sel;
			} else if ((5 - i) > dekaronDay) {
				dateArray.className = 'challenge_date_running_3';
			} else if ((5 - i) < dekaronDay) {
				dateArray.className = 'challenge_date_running_3 selected';
			}
		} else {

			//alert(dateArray.innerHTML)
			if (dateArray.innerHTML == dekaronDay) {
				dateArray.className = 'challenge_date_running_3 ' + sel;
			} else if (dekaronDay < i) {
				dateArray.className = 'challenge_date_running_3';

			} else if (dekaronDay > i) {
				dateArray.className = 'challenge_date_running_3 selected';
			}
		}

	}

	var dr1 = document.getElementById('date_running_3_1');

	if (dekaronDay >= 29) {
		sl.style.display = 'none';
		sl1.style.display = 'block';
//		dr1.style.marginLeft = 10 + "px";
	} else {
		sl1.style.display = 'none';
//		dr1.style.marginLeft = 0 + "px";
	}

	if (dekaronDay == 30) {
		var six = document.getElementById("date_running_3_30");
		six.className = 'challenge_date_running ' + sel;
	}
	
}

//绑定挑战进行中累计模板数据
function bingDataForCount(data){
	var type = data.dekaron.valueType;
	
	var nowDay=data.dekaronDay;
	
	var updateRecordDay=data.updateRecordDay;
	if(updateRecordDay==0){
		updateRecordDay=updateRecordDay+1;
	}
	
	var dekaronDay=30-updateRecordDay;

	//document.getElementById("day_text_running_2").innerHTML = dekaronDay;
	//已完成数
	var overCount = data.fulfill;
	//总数
	var totalCount = 0;
	//进度条百分比
	var bfb = 0;
	var leftText;
	var rightText;
	var valueText=document.getElementById("step_text_running_2");

	var danweiText=document.getElementById("danwei_text_2");
	
	
	
	if (type == 1) {
		totalCount = data.dekaron.stepValue;
		if (totalCount - overCount < 10000) {
			//						leftText = (overCount/10000).toFixed(2);
			//						rightText = totalCount - overCount;
//			console.log(overCount+"---"+(totalCount-overCount));
			leftText = showDecimalOne(overCount / 10000);
			rightText = parseFloat((totalCount - overCount).toFixed(1));
//			console.log(leftText+"---"+rightText);
			if (rightText <= 0) {
//				hiddenDom('challengeDiv_running_2');
//				alert("恭喜！当前挑战已完成。");
			}
			valueText.innerHTML=rightText;
			leftText = leftText + '万步';
			rightText = rightText + '步';
			danweiText.innerHTML="&nbsp;步";
			
		} else {
			//						leftText = (overCount/10000).toFixed(2);
			//						rightText = ((totalCount - overCount)/10000).toFixed(2);
			
			leftText = parseFloat(parseFloat(overCount / 10000).toFixed(1));
			rightText = showDecimalOne(((totalCount - overCount) / 10000).toFixed(2));
			
//			leftText=getInt(leftText);
			valueText.innerHTML=rightText;
			leftText = leftText + '万步';
			rightText = rightText + '万步';
			danweiText.innerHTML="&nbsp;万步";
			
		}
		bfb = (overCount / totalCount) * 100;
		tempTwoShow(leftText, rightText, bfb,nowDay);
		
		
		
	}

	if (type == 2) {
		totalCount = data.dekaron.calorieValue;
		if (totalCount - overCount < 1) {
			//						leftText = overCount;
			//						rightText = ((totalCount - overCount) * 1000).toFixed(1);
			//						leftText = getInt(leftText) + '大卡';
			//						rightText = getInt(rightText) + '卡';
			//						if(getInt(rightText)<=0){
			//							hiddenDom('challengeDiv_running_2');
			//							alert("恭喜！当前挑战已完成。");							
			//						}
//			console.log(overCount+"---"+(totalCount-overCount));
			
			leftText = showDecimalOne(parseFloat(overCount).toFixed(2));
			rightText = parseFloat(((totalCount - overCount) *1000).toFixed(0));

//			console.log(leftText+"---"+rightText);
			if (rightText <= 0) {
				hiddenDiv('challengeDiv_running_2');
				alert("恭喜！当前挑战已完成。");
			}
			valueText.innerHTML=rightText;
			leftText = leftText + '大卡';
			rightText = rightText + '卡';
			danweiText.innerHTML="&nbsp;卡";
		} else {
			//						leftText = (parseFloat(overCount)).toFixed(1);
			//						rightText = (totalCount - overCount).toFixed(1);
			//						leftText = getInt(leftText) + '大卡';
			//						rightText = getInt(rightText) +'大卡';
//			console.log(overCount+"---"+(totalCount-overCount));
			
			leftText = parseFloat(parseFloat(overCount).toFixed(1));
			rightText = showDecimalOne((totalCount - overCount).toFixed(2));
//			leftText=getInt(leftText);
//			console.log(leftText+"---"+rightText);
			valueText.innerHTML=rightText;
			leftText = leftText + '大卡';
			rightText = rightText + '大卡';
			danweiText.innerHTML="&nbsp;大卡";

		}
		bfb = (overCount / totalCount) * 100;
		tempTwoShow(leftText, rightText, bfb,nowDay);
		
	}
	if (type == 3) {
		totalCount = data.dekaron.distanceValue;
		if (totalCount - overCount < 1) {
			//						leftText = overCount;
			//						rightText = ((totalCount - overCount) * 1000).toFixed(1);
			//						leftText = getInt(leftText) + '公里';
			//						rightText = getInt(rightText) + '米';
			//						if(getInt(rightText)<=0){
			//							hiddenDom('challengeDiv_running_2');
			//							alert("恭喜！当前挑战已完成。");							
			//						}
//			console.log(overCount+"---"+(totalCount-overCount));
			leftText = showDecimalOne(overCount);
			rightText = parseFloat(((totalCount - overCount) * 1000).toFixed(1));
//			console.log(leftText+"---"+rightText);
			if (rightText <= 0) {
				hiddenDiv('challengeDiv_running_2');
				alert("恭喜！当前挑战已完成。");
			}
//			console.log(leftText+"---"+rightText);
			valueText.innerHTML=rightText;
			leftText = leftText + '公里';
			rightText = rightText + '米';
			danweiText.innerHTML="&nbsp;米";

		} else {
			//						leftText = (parseFloat(overCount)).toFixed(1);
			//						rightText = (totalCount - overCount).toFixed(1);
			//						leftText = getInt(leftText) + '公里';
			//						rightText = getInt(rightText) +'公里';
//			console.log(overCount+"---"+(totalCount-overCount));
			leftText = parseFloat(parseFloat(overCount).toFixed(1));
			rightText = showDecimalOne((totalCount - overCount).toFixed(2));
//			console.log(leftText+"---"+rightText);
//			leftText=getInt(leftText);
			valueText.innerHTML=rightText;
			leftText = leftText + '公里';
			rightText = rightText + '公里';
//			console.log(leftText+"---"+rightText);
			danweiText.innerHTML="&nbsp;公里";
		}
		bfb = (overCount / totalCount) * 100;
		tempTwoShow(leftText, rightText, bfb,nowDay);
		
	}
	
}

//模板二显示方式
function tempTwoShow(leftText, rightText, bfb,nowDay) {
	document.getElementById("step_left_running_2").style.width = bfb + "%";
	document.getElementById("step_right_running_2").style.width = (100 - bfb)
			+ "%";
	document.getElementById("step_left_running_2").innerHTML = leftText;
	document.getElementById("step_right_running_2").innerHTML = rightText;
	//document.getElementById("step_text_running_2").innerHTML = rightText;
	
	if (bfb < 25) {
		document.getElementById("step_left_running_2").innerHTML = "";
	}
	if (bfb > 75) {
		document.getElementById("step_right_running_2").innerHTML = "";
	}
	
	if(nowDay<0){
		nowDay=Math.abs(nowDay);
		var day =8-nowDay;
		//var text=document.getElementById("challenge_reward_running_2");
		var chan2_text=document.getElementById("chan2_text");
		chan2_text.style.display="none";
		var text=document.getElementById("chan2_dateCount");
		if(day==1){
			text.innerHTML='挑战将在今天过期，请及时同步数据！';
		}
		else{
			text.innerHTML='<span style="margin-left:5px;">挑战将在'+day+'天后过期，请及时同步数据！</span>';
		}
		
	}
}


//显示明天开始的模板
function showStartTomorrow(data){
	
	var template=data.dekaron.template;
	switch(template){
	
		case 1:
			
			weekTemplate(data);
			break;
			
		case 2:
			
			countTemplate(data);
			break;
			
		case 3:
			
			monthTemplate(data);
			break;
		
	}
}

//显示明天开始周模板
function weekTemplate(data){
	showDiv("showTorChallengeInfoDiv_1");
	//showDiv("challengeTaget_div_1");
	
	var type=data.dekaron.valueType;
	var countDay=document.getElementById("count_day_1");
	var countValue=document.getElementById("count_value_1");
	countDay.innerHTML="连续&nbsp;"+data.dekaron.finishTime+"&nbsp;天";
	
	if(type==1){
		countValue.innerHTML= data.dekaron.stepValue+ "&nbsp;步";
	}
	else if(type==2){
		countValue.innerHTML= data.dekaron.calorieValue+ "&nbsp;大卡";
		
	}
	else if(type==3){
		countValue.innerHTML= data.dekaron.distanceValue+ "&nbsp;公里";
	}
}

//显示明天开始月模板
function monthTemplate(data){
	showDiv("showTorChallengeInfoDiv_3");
	//showDiv("challengeTaget_div_1");
	
	var type=data.dekaron.valueType;
	var countDay=document.getElementById("count_day_3");
	var countValue=document.getElementById("count_value_3");
	countDay.innerHTML="连续&nbsp;"+data.dekaron.finishTime+"&nbsp;天";
	
	if(type==1){
		countValue.innerHTML= data.dekaron.stepValue+ "&nbsp;步";
	}
	else if(type==2){
		countValue.innerHTML= data.dekaron.calorieValue+ "&nbsp;大卡";
		
	}
	else if(type==3){
		countValue.innerHTML= data.dekaron.distanceValue+ "&nbsp;公里";
	}

}

//显示明天开始累计模板
function countTemplate(data){
	showDiv("showTorChallengeInfoDiv_2");
	//showDiv("challengeTaget_div_2");
	
	var type=data.dekaron.valueType;
	var proText=document.getElementById("pro_text");
	var countDay=document.getElementById("count_day_2");
	var countValue=document.getElementById("count_value_2");
	countDay.innerHTML="&nbsp;"+data.dekaron.finishTime+"&nbsp;天&nbsp;累积";
	
	if(type==1){
		var stepValue = data.dekaron.stepValue >= 10000 ? (data.dekaron.stepValue / 10000 + "&nbsp;万"): data.dekaron.stepValue+"&nbsp;";
		var avgValue=parseInt(data.dekaron.stepValue/30);
		countValue.innerHTML= avgValue + "步";
		proText.innerHTML= stepValue + "步";
	}
	else if(type==2){
		var calorieValue=data.dekaron.calorieValue;
		var avgValue=parseInt(calorieValue/30);
		countValue.innerHTML= avgValue+ "&nbsp;大卡";
		proText.innerHTML=data.dekaron.calorieValue+ "&nbsp;大卡";
	}
	else if(type==3){
		var distanceValue=data.dekaron.distanceValue;
		var avgValue=parseInt(distanceValue/30);
		countValue.innerHTML= avgValue+ "&nbsp;公里";
		proText.innerHTML=data.dekaron.distanceValue+ "&nbsp;公里";
	}
}

/**
 * 截取保留一位小数  (不四舍五入  小数点后为0取整数)  注：保留两位小数四舍五入之后
 * 
 */
function getDecimalOne(str) {
	var temp = str + "";
	var flag = parseFloat(str);
	if(temp.indexOf(".")>0){
		temp = flag.toFixed(2) + "";
		temp = temp.substring(0, temp.indexOf(".")+2);
	}
//	str = str.indexOf(".") < 0 ? str : (str.toFixed(2)+"").substring(0, str.indexOf(".") + 2);
	return parseFloat(temp);
}
/**
 * 截取保留一位小数
 * @param str
 */
function showDecimalOne(str){
	str = str +"";
	str = str.indexOf(".") < 0 ? str : (str.substring(0, str.indexOf(".") + 2));
	return parseFloat(str);
}

